<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>点击</button>
    <script>
    //call()改变this指向，实现继承
        function Father(name,age){
            this.name=name;
            this.age=age;
        }
        function Son(name,age){
            Father.call(this,name,age);
        }
        var son=new Son("张三",13);
        console.log(son);
    //apply()改变this指向，实现求最大值
        var arr=[1,29,20,199];
        var max=Math.max.apply(Math,arr);
        console.log(max);
    //bind()改变this指向，返回原函数拷贝
        var o={
            name:'sam'
        }
        function fn(){
            console.log(this);
        }
        var f=fn.bind(o);
        f();
    //bind（）实现按钮禁用2秒功能
        var btn=document.querySelector('button');
        btn.onclick=function(){
            this.disabled=true;
            setTimeout(function() {//定时器
                this.disabled=false;
            }.bind(this), 2000);//这个this绑定函数内this指向btn对象
        }
    </script>
</body>
</html>